package com.yuanlp.shoppingmall.home.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yuanlp.shoppingmall.R;
import com.yuanlp.shoppingmall.home.model.ResultBeanData;
import com.yuanlp.shoppingmall.utils.Constants;

import java.util.List;

/**
 * Created by 原立鹏 on 2017/8/29.
 */

public class HotAdapter extends BaseAdapter {

    private final Context context;
    private final List<ResultBeanData.ResultBean.HotInfoBean> hot_info;

    public HotAdapter(Context context, List<ResultBeanData.ResultBean.HotInfoBean> hot_info) {
        this.context=context;
        this.hot_info=hot_info;
    }

    @Override
    public int getCount() {
        return hot_info.size();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=new ViewHolder();
        if (convertView==null){
            convertView=View.inflate(context, R.layout.item_hot,null);
            holder.iv_hot= (ImageView) convertView.findViewById(R.id.iv_hot);
            holder.tv_name= (TextView) convertView.findViewById(R.id.tv_name);
            holder.tv_price= (TextView) convertView.findViewById(R.id.tv_price);
            convertView.setTag(holder);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }
        ResultBeanData.ResultBean.HotInfoBean hotInfoBean = hot_info.get(position);
        Glide.with(context).load(Constants.IMG_URL+hotInfoBean.getFigure()).into(holder.iv_hot);
        holder.tv_name.setText(hotInfoBean.getName());
        holder.tv_price.setText(hotInfoBean.getCover_price());
        return convertView;
    }

    @Override
    public Object getItem(int position) {
        return hot_info.get(position);
    }


    @Override
    public long getItemId(int position) {
        return position;
    }


    class ViewHolder {
        ImageView iv_hot;
        TextView tv_price;
        TextView tv_name;
    }

}
